package com.cike.sparkstudy.sparkstreaming.scala

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Durations, StreamingContext}

object WordCount {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[2]").setAppName("WordCount")
    val ssc = new StreamingContext(conf,Durations.seconds(1))

    val lines = ssc.socketTextStream("bigdata",9999)
    val words = lines.flatMap{line => line.split(" ")}
    val pairs = words.map{word => (word,1)}
    val wordCounts = pairs.reduceByKey(_+_)

    Thread.sleep(10000)
    wordCounts.print()
    ssc.start()
    ssc.awaitTermination()

  }

}
